/**
 * @author 	mikegill74
 * @devcid 	TSTDRV820439
 * @livecid	
 */

 function REST_SuiteLet(request, response){
 	
	if (request.getMethod() == 'GET'){
		try {
			
			if (request.getParameter('dmltype') == 'insert') {
				var recordId = AddCustomer();
			}
			
			else if (request.getParameter('dmltype') == 'update'){
				
			}
			form = nlapiCreateForm('Insert Customer', true);
			var field = form.addField('custpage_custid','text','Customer Id:');
			field.setDefaultValue(recordId);
			field.setDisplayType('inline');
			var field = form.addField('custpage_para','text','URL parameter value:');
			field.setDefaultValue(request.getParameter('dmltype'));
			field.setDisplayType('inline');
		
			response.writePage(form);
		}
		
		catch (e){
				var recordId = AddCustomer();
				form = nlapiCreateForm('Insert Customer Failed', true);
				var field = form.addField('custpage_custid','text','Error');
				field.setDefaultValue(e.getCode() + '\n' + e.getDetails());
				response.writePage(form);
		}
	
		
	}
	
	else {
		
	}
 }
 
 function AddCustomer(){
 	
	var customerRecord = nlapiCreateRecord('customer');
	//customerRecord.setFieldValue('entityid', 'Test');
	customerRecord.setFieldValue('companyname', 'Elvis');
	var customerId = nlapiSubmitRecord(customerRecord, true, false);
	nlapiLogExecution('debug','Customer record inserted successfully', customerId);
	return customerId;
	
 }
 
 function UpdateCustomer(recordId){
 	
 }
